import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

/*
* state commit
* action dispatch
* mutation
*
* */
export default new Vuex.Store({
  state: {
    a:1
  },
  getters:{
    geta(state){
      console.log(arguments[1] == arguments[3])
      return state.a + 1
    }
  },
  mutations: {
    increase(state){
      console.log(arguments);
      state.a+=2
    }
  },
  actions: {
    increase({commit}){
      console.log(arguments);
      commit('increase')
    }
  },
  modules: {
    account: {
      namespaced: true,

      // 模块内容（module assets）
      state: () => ({ }), // 模块内的状态已经是嵌套的了，使用 `namespaced` 属性不会对其产生影响
      getters: {
        isAdmin () { } // -> getters['account/isAdmin']
      },
      actions: {
        login () { } // -> dispatch('account/login')
      },
      mutations: {
        login () { } // -> commit('account/login')
      },

      // 嵌套模块
      modules: {
        // 继承父模块的命名空间
        myPage: {
          state: () => ({}),
          getters: {
            profile () {} // -> getters['account/profile']
          }
        },
        // 进一步嵌套命名空间
        posts: {
          namespaced: true,

          state: () => ({}),
          getters: {
            popular () {} // -> getters['account/posts/popular']
          }
        }
      }
    }
  }
})
